package com.muqi.app.user.widget;


import java.util.List;

import com.bumptech.glide.Glide;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.project.utils.ScreenUtils;
import com.muqi.app.qlearn.adapter.CommentAdapter;
import com.muqi.app.qlearn.adapter.CommonAdapter;
import com.muqi.app.qlearn.adapter.CommonViewHolder;
import com.muqi.app.qlearn.modles.Subject;
import com.muqi.app.qlearn.modles.VedioInfo;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.qlearn.student.ui.VedioListActivity;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class SubjectWindow extends PopupWindow implements OnItemClickListener {
	private View conentView;
	private Context mContext;
	private List<Subject> listData;
	private TextView mItemName;

	public interface ClickSubjectListener {
		void onClickSubjectListener(int position);
	}

	private ClickSubjectListener clickClubWindowListener;

	@SuppressWarnings("deprecation")
	public SubjectWindow(final Activity context,List<Subject> listData,
			ClickSubjectListener clickClubWindowListener) {
		this.clickClubWindowListener = clickClubWindowListener;
		this.mContext = context;
		this.listData=listData;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_subject, null);
		// int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w / 3 + 110);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		
		ListView lv=(ListView) conentView.findViewById(R.id.subject_lv);
		adapter =new CommonAdapter<Subject>(mContext, listData, R.layout.item_subject) {

			@Override
			protected void convertView(View item, Subject t) {
				if(t!=null){
					mItemName=CommonViewHolder.get(item, R.id.item_name);
					mItemName.setText(t.name);
				}
				
			}
			
			
		};
		lv.setAdapter(adapter);
		lv.setOnItemClickListener(this);
		

	}

	/**
	 * showPopupWidow
	 * 
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			this.showAsDropDown(parent, 0, 5);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		if (clickClubWindowListener != null) {
			clickClubWindowListener.onClickSubjectListener(position);
		}
		SubjectWindow.this.dismiss();

	}
	private CommonAdapter<Subject> adapter;
}